﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Word;
using FieldTFS = Microsoft.TeamFoundation.WorkItemTracking.Client.Field;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using WordTemplate1;
using WordTemplate1.Objets;

namespace Methodes.WordTemplate1
{
    /// <summary>
    /// Gestion des contenus
    /// </summary>
    public class Contents
    {
        /// <summary>
        /// Permet d'ajouter un ensemble de balise pour l'ajout de données
        /// </summary>
        /// <param name="type"></param>
        /// <param name="title"></param>
        /// <param name="text"></param>
        internal static Microsoft.Office.Interop.Word.ContentControl AddContentText(EField element)
        {
            string title =  Globals.ThisDocument.IdentifiantContent + "|" + element.Workitem.Id + "|" + element.ReferenceName;
            string text = element.ValueTFS.ToString();

            Microsoft.Office.Interop.Word.ContentControl content;
            content = Globals.ThisDocument.ContentControls.Add(element.wdContentControl);
            content.Title = title;
            content.Range.Text = text;
            content.LockContents = element.ReadOnly;

            element.AddContentControl(content);

            return content;
        }

        /// <summary>
        /// Permet de connaitre les champs par défault en read only
        /// </summary>
        /// <param name="champ"></param>
        /// <returns></returns>
        internal static bool GetReadOnly(string champ)
        {
            string[] champs = new string[] { "system.id","system.rev" };

            if(champs.Contains(champ.ToLower()))
                return true;
            else
                return false;
        }

        /// <summary>
        /// Permet d'ajouter un bloc de modèle
        /// </summary>
        public static void AddContentBlock()
        {
            Microsoft.Office.Interop.Word.ContentControl content;
            content = Globals.ThisDocument.ContentControls.Add(WdContentControlType.wdContentControlBuildingBlockGallery);
            content.BuildingBlockType = WdBuildingBlockTypes.wdTypeQuickParts;
            content.BuildingBlockCategory = Globals.ThisDocument.CATEGORIE1;
            content.Title = "Insert block for Team For Word";

        }
    }
}
